/**
 * Created by bitfeng on 16/4/26.
 */
var webPage = require('webpage');
var page = webPage.create();

var url = "http://www.lagou.com/zhaopin/Java/?labelWords=label";
console.log(url);

// 打印页面标题
function print_title(page){
    var title = page.evaluate(function(){
        return document.title;
    });
    console.log(title);
}

// 获取当前页面
function get_current_page(page){
    var page_now = page.evaluate(function(){
        return document.getElementsByClassName('pager_is_current')[0];
    });
    return page_now.textContent.trim();
}

// click动作, 使用evaluate
function pagedown(page){
    console.log('start PageDown');
    page.evaluate(function(){
        document.getElementsByClassName('pager_next ')[0].click();
    });
    console.log('finish PageDown');
}

// click动作, 使用evaluateJavaScript
function pagedown_script(page){
    console.log('start PageDown');
    var script = "function(){document.getElementsByClassName('pager_next ')[0].click();}";
    page.evaluateJavaScript(script);
    console.log('finish PageDown');
}


page.open(url, function(status) {
    console.log('HTTP Status: '+status);
    print_title(page);

    console.log('Page_current: '+get_current_page(page));
    //pagedown(page);
    pagedown_script(page);
    console.log('Page_current: '+get_current_page(page));

    pagedown_script(page);
    console.log('Page_current: '+get_current_page(page));

    phantom.exit();
});